import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:jtsell_app/config/app_config.dart';
import 'package:jtsell_app/entity/user_login_entity.dart';
import 'package:jtsell_app/provider/user_login_model.dart';
import 'package:jtsell_app/routes/routes.dart';
import 'package:jtsell_app/widget/arc_banner_image.dart';
import 'package:provider/provider.dart';

import '../r.dart';

class MemberPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return new MemberPageState();
  }
}

class MemberPageState extends State<MemberPage> {
  ///
  /// 头部用户信息
  ///
  Widget _getMemberHead(UserLoginModel userLoginModel) {
    final UserLoginEntity _userLoginEntity = userLoginModel.userLoginEntity;

    return Container(
      color: Colors.white,
      child: Stack(
        alignment: Alignment(0.0, 1.0),
        children: [
          Padding(
            padding: const EdgeInsets.only(bottom: 25.0),
            child: ArcBannerImage(),
          ),
          Positioned(
            bottom: 0.0,
            child: Container(
              child: InkWell(
                onTap: () {
                  if (_userLoginEntity == null) {
                    Routes.getInstance().loginPage(context);
                  }
                },
                child: Column(
                  children: <Widget>[
                    SizedBox(
                      width: ScreenUtil().setWidth(200),
                      height: ScreenUtil().setWidth(200),
                      child: CircleAvatar(
                        backgroundImage: _userLoginEntity == null
                            ? AssetImage(
                                R.IMG_600,
                              )
                            : NetworkImage(_userLoginEntity.imageUrl),
                      ),
                    ),
                    Container(
                      margin: new EdgeInsets.only(
                        top: 10.0,
                      ),
                      child: new Text(
                        _userLoginEntity == null ? '点击登录' : _userLoginEntity.buyerName,
                        style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  ///
  /// 我的订单
  ///
  Widget _myOrder() {
    return Container(
      color: Colors.white,
      child: Row(
        children: <Widget>[
          Icon(
            Icons.receipt,
            color: Colors.black54,
            size: 23.0,
          ),
          SizedBox(
            width: ScreenUtil().setWidth(20),
          ),
          Text(
            '我的订单',
            style: TextStyle(fontSize: 16.0),
          )
        ],
      ),
      margin: new EdgeInsets.only(left: 15.0, top: 8.0),
    );
  }

  ///
  /// 订单状态管理
  ///
  Widget _orderStatus() {
    return
        //第四个部分
        Container(
      color: Colors.white,
      margin: new EdgeInsets.only(top: 10.0, bottom: 1.0),
      child: new Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: <Widget>[
          Column(
            children: <Widget>[
              Icon(
                Icons.euro_symbol,
                color: Colors.orange,
                size: 25.0,
              ),
              Container(
                margin: new EdgeInsets.only(top: 5.0),
                child: Text('待付款', style: TextStyle(fontSize: 13.0)),
              ),
            ],
          ),
          Column(
            children: <Widget>[
              Icon(
                Icons.restore,
                color: Colors.orange,
                size: 25.0,
              ),
              Container(
                margin: new EdgeInsets.only(top: 5.0),
                child: Text(
                  '待发货',
                  style: TextStyle(fontSize: 13.0),
                ),
              ),
            ],
          ),
          Column(
            children: <Widget>[
              Icon(
                Icons.print,
                color: Colors.orange,
                size: 25.0,
              ),
              Container(
                margin: new EdgeInsets.only(top: 5.0),
                child: Text('待收货', style: TextStyle(fontSize: 13.0)),
              ),
            ],
          ),
          Column(
            children: <Widget>[
              Icon(
                Icons.feedback,
                color: Colors.orange,
                size: 25.0,
              ),
              Container(
                margin: new EdgeInsets.only(top: 5.0),
                child: Text('待评价', style: TextStyle(fontSize: 13.0)),
              ),
            ],
          ),
        ],
      ),
    );
  }

  ///
  ///列表
  ///
  Widget _listTile(String title, {IconData icons = Icons.receipt, Color color = Colors.black26}) {
    return Container(
      decoration: BoxDecoration(
          color: Colors.white,
          border: Border(bottom: BorderSide(width: 0.5, color: Colors.black12))),
      child: ListTile(
        leading: Icon(
          icons,
          color: color,
        ),
        title: Text(title),
        trailing: Icon(Icons.chevron_right, color: Colors.black26),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    ///
    /// 用户登录后更新用户信息
    ///
    return Consumer<UserLoginModel>(
        builder: (BuildContext context, UserLoginModel userLoginModel, Widget child) {
      return Scaffold(
        appBar: PreferredSize(
            child: _getMemberHead(userLoginModel),
            preferredSize: Size.fromHeight(ScreenUtil().setHeight(400))),
        body: Container(
          color: Colors.white,
          child: ListView(
            children: <Widget>[
              //第二个部分
              Container(
                color: Colors.white,
                margin: new EdgeInsets.only(top: 30.0, bottom: 1.0),
                child: new Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[
                    Column(
                      children: <Widget>[
                        Icon(
                          Icons.star,
                          color: Colors.redAccent,
                          size: 25.0,
                        ),
                        Container(
                          child: Text(
                            '收藏',
                            style: TextStyle(fontSize: 13.0),
                          ),
                        ),
                      ],
                    ),
                    Column(
                      children: <Widget>[
                        Icon(
                          Icons.comment,
                          color: Colors.blue,
                          size: 25.0,
                        ),
                        Container(
                          child: Text('评价', style: TextStyle(fontSize: 13.0)),
                        ),
                      ],
                    ),
                    Column(
                      children: <Widget>[
                        Icon(
                          Icons.watch_later,
                          color: Color(0xFF4DD0E1),
                          size: 25.0,
                        ),
                        Container(
                          child: Text('足迹', style: TextStyle(fontSize: 13.0)),
                        ),
                      ],
                    ),
                  ],
                ),
              ),

              ///
              /// 订单顶部分割线
              ///
              Container(
                color: Colors.white,
                child: Divider(
                  color: Colors.black12,
                  height: 2.0,
                ),
                margin: new EdgeInsets.only(top: 10.0),
              ),

              ///
              /// 我的订单
              ///
              _listTile("我的订单"),

              ///
              /// 订单状态
              ///
              _orderStatus(),
              Container(
                color: Colors.white,
                child: Divider(
                  color: Colors.black12,
                  height: 2.0,
                ),
                margin: new EdgeInsets.only(top: 10.0),
              ),
              _listTile("领取优惠券", icons: Icons.favorite_border, color: Colors.red),
              _listTile("已领取优惠券", icons: Icons.favorite_border, color: Colors.orange),
              _listTile("地址管理", icons: Icons.location_on, color: Colors.lightGreen),
              Container(
                padding: EdgeInsets.only(bottom: ScreenUtil().setHeight(30)),
                color: Color(0x10000000),
              ),
              _listTile("客服电话", icons: Icons.face, color: Colors.pinkAccent),
              _listTile("关于商城", icons: Icons.info, color: Colors.blue),
              //第5个部分
            ],
          ),
        ),
      );
    });
  }
}
